<?php
namespace Org;
require("simple_html_dom.php");
//header('Content-type:text/html');
class getread{
    public function read($id){
        $url='http://'.$_SERVER['HTTP_HOST'];
        //echo dirname($url);
        $url = $url.__ROOT__."/api.php?r=l/d&id=".$id."&u=440115";
        $f=curl($url);
        
        $b=parser($f);
        return $b;
    }
}




function curl($url){
    $url = $url;
    $headers = array("User-Agent"=>"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Mobile Safari/537.36");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $output = curl_exec($ch);
    curl_close($ch);
    //打印获得的数据
    return ($output);
}

function parser($text){
// 新建一个Dom实例
$html = new simple_html_dom();

// 从url中加载
//$html->load_file('http://www.jb51.net');

// 从字符串中加载
$html->load($text);
if($html->find("div[class=detail-row clearfix]",0)==NULL){
    return NULL;
}else{

//从文件中加载
//$html->load_file('path/file/test.html');
$good->title=$html->find("div[class=detail-row clearfix]",0)->find("span[class=title]",0)->innertext;

$good->tuijian=$html->find("div[class=detail-row clearfix]",0)->find("span[class=theme-color-3]",0)->innertext;
if(count($html->find("div[class=detail-row clearfix]",0)->find("div[class=buy-coupon theme-color-8]",0))!=0){
    $good->qprice=$html->find("div[class=detail-row clearfix]",0)->find("div[class=buy-coupon theme-color-8]",0)->find("b",0)->innertext;
}


$good->quan=$html->find("div[class=detail-row clearfix]",0)->find("a",0)->href;

$good->img=$html->find("div[class=detail-row clearfix]",0)->find("img",0)->src;

$good->now_price=$html->find("div[class=detail-row clearfix]",0)->find("span[class=now-price]",0)->find("i",0)->innertext;
$good->old_price=$html->find("div[class=detail-row clearfix]",0)->find("span[class=org-price]",0)->find("i",0)->innertext;
$good->sell=$html->find("div[class=detail-row clearfix]",0)->find("div[class=text-wrap]",0)->find("i",0)->innertext;

$good->goodid=$html->find("div[class=detail-row clearfix]",0)->find("a",0)->attr["biz-itemid"];
return json_encode($good);
    
}
}


    

